package com.test.exam.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.test.exam.domain.Ban;
import com.test.exam.service.BanService;

@Controller
public class BanController {
	@Autowired
	private BanService banService;
	
	// 현재 페이지 반 목록 
	@RequestMapping(value="/admin/ban/getBansByCurrentPage/{currentPage}", method=RequestMethod.GET)
	public String getBansByCurrentPage(
			@PathVariable int currentPage, 
			Model model){
		model.addAttribute(
				"banList", 
				banService.getBansByCurrentPage(currentPage));
		
		model.addAttribute("currentPage", currentPage);
		model.addAttribute("endPage", banService.getEndPage());
		
		return "/admin/ban/banList";
	}
	
	//반 추가	폼 이동
	@RequestMapping(value="/admin/ban/addBanForm", method=RequestMethod.GET)
	public String addBanForm(){
		return "/admin/ban/addBanForm";
	}
	
	//반 추가
	@RequestMapping(value="/admin/ban/addBan", method=RequestMethod.POST)
	public String addBan(Ban ban){
		banService.addBan(ban);
		return "redirect:/admin/ban/getBansByCurrentPage/1";
	}
}









